package com.example.demo.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.example.demo.custom.BaseRepository;
import com.example.demo.entity.CarsOrder;
import com.example.demo.entity.CarsOrder2;
import com.example.demo.entity.NewCar1;
import com.example.demo.entity.UsedCar1;

@Repository
public interface CarsOrder2Repository extends BaseRepository<CarsOrder2, Integer> {

	List<CarsOrder2> findByCarsorder(CarsOrder carsOrder);

	List<CarsOrder2> findByCars(NewCar1 car);

	List<CarsOrder2> findByCars2(UsedCar1 car);
	// @Query("select B from CarsOrder A left join CarsOrder2 B on B.carsorder = A")
	// List<CarsOrder2> findByCarsorderId(CarsOrder car);

//	@Query(value="SELECT * FROM cars_order2 q where q.id>(SELECT t.id FROM cars_order2 t WHERE t.carsorder_id=?1)",nativeQuery=true)
//	@Query(value = "SELECT * FROM cars_order2 t INNER JOIN cars_order a ON t.carsorder_id=?1 ORDER BY t.begin_date",nativeQuery=true)
//	List<CarsOrder2> findByCarsorderId(Integer car);
	
	/**
	 * @param car
	 * @return 通过时间排序得到最新一条
	 */
	@Query(value = "SELECT  *  FROM cars_order2 t WHERE t.carsorder_id=? ORDER BY t.begin_date DESC LIMIT 1 ",nativeQuery=true)
	CarsOrder2 findByCarsorderId(Integer car);
}
